
// router.js
import { createRouter, createWebHistory } from 'vue-router';

// 引入组件
import MainPage from '../pages/MainPage.vue';
import LoginPage from '../pages/LoginPage.vue';

import Feedback from '../pages/Feedback.vue';
import HomePage from '../pages/HomePage.vue';
import Product from '../pages/ProductPage.vue';
import Account from '../pages/AccountPage.vue';

// 定义路由
const routes = [
  {
    path: '/', component: MainPage,
    redirect: '/Main/Feedback'
  },
  { path: '/Login', component: LoginPage },
  {
    path: '/Main',
    component: MainPage,
    redirect: '/Main/Feedback',
    children: [
      { path: '/Main/Feedback', component: Feedback },
      { path: '/Main/HomePage', component: HomePage },
      { path: '/Main/Account', component: Account },
      { path: '/Main/Product', component: Product }
    ]
  },
];

// 创建router实例
const router = createRouter({
  history: createWebHistory("#"),
  mode: 'hash',
  routes,
});


// router.beforeEach((to, from) => {
//   // console.log(to); // 去哪儿
//   console.log(from); // 从哪儿来
//   if (to.meta.requiresAuth == true) {
//     let token = window.localStorage.getItem("token")
//     if (token == null || token == "") {
//       // message.warning("登录失效")
//       router.push("/admin/login")
//       return false;
//     }
//     // 校验Token合法性
//     checkLoginState().then(response => {
//       let data = response.date
//       if (data.code == 200) {
//         return true
//       } else {
//         // message.warning(data.msg)
//         router.push("/admin/login")
//         return false;
//       }
//     })

//   }
//   return true;
// });

export default router;